clear,clc,close all
x_altitute=[
   63.3214
   68.0138
   73.9859
   81.6644
   85.5037
  111.0986
  118.3505
  129.4417
  144.7987
  150.7708
  186.6037
  194.2822
  201.1076
  203.2405
  213.0519
  226.7025
  231.3949
  240.3531
  248.0316
  256.9899
  267.6544
  279.1722
  285.9975
  291.9696
  297.9418
  302.2076
  311.5924
  313.7254
  321.0000
  330.6109
  337.6495
  347.5036
  352.6652
  357.3577 
  363.4578
  376.4330
  389.6571
  396.0558
  401.1748
  406.7204
  418.6647
  433.1685
  440.8470
  476.2533
  483.9318
  489.9040
  496.3027
  500.8687
  516.3521
  521.4711
  532.5622
  539.8141
  546.6394
  556.8774
  568.3952
  582.8990
  591.8572
  596.9762
  600.3888
  605.0813
  610.6268
  617.4521
  627.2635
  633.2357
  643.4737];
y_altitude=[59.2706
   60.5504
   60.9770
   66.9491
   66.5225
   91.2643
   86.9985
   92.5441
   80.1732
   78.0403
   54.5782
   40.9276
   37.9415
   38.3681
   48.6061
   54.5782
   61.4035
   63.1099
   67.3757
   79.7466
   80.5998
   67.8023
   64.3896
   59.6972
   60.9770
   61.4035
   66.9491
   67.3757
   64.0000
   67.7883
   61.6882
   61.2189
   59.3420
   60.2804
   62.1574
   68.6554
   83.1593
   86.5719
   90.8377
   87.8517
   92.5441
   79.3200
   78.8934
   54.1516
   40.5010
   37.5149
   40.0744
   47.7971
   54.1516
   63.1099
   63.9630
   69.9352
   79.3200
   80.1732
   69.5086
   61.4035
   60.9770
   65.6694
   66.0959
   68.2289
   65.2428
   69.5086
   62.2567
   60.5504
   58.4175];
%% 
H=imread([cd '\赛道.png']);
H1=H(250:650,:,:);
H2=H(850:end,40:680,:);
figure(),imshow(H2)
hold on
plot(x_altitute-40,y_altitude,'LineWidth',4,'Color','cyan')

load map_xy.mat
figure()
imshow(H1)
hold on
% p=1;
% while 1
%     pause();
%     [i j]=ginput(1);
%     x=[x;i];y=[y;j];
%     hold on
%     scatter(x(p),y(p),'r*')
%     p=p+1;
% end
plot([x;x(1)],[y;y(1)],'LineWidth',3,'Color','cyan')

figure()
plot([x;x(1)],-[y;y(1)],'LineWidth',3)
for i=2:length(x)-1
    tur(i-1,1)=acos((dist([x(i-1) y(i-1)],[x(i);y(i)])^2+dist([x(i) y(i)],[x(i+1);y(i+1)])^2-dist([x(i-1) y(i-1)],[x(i+1);y(i+1)])^2)/(2*dist([x(i-1) y(i-1)],[x(i);y(i)])*dist([x(i) y(i)],[x(i+1);y(i+1)])));
end
for i=1:length(tur)
    if tur(i)>pi/2
        type(i,1)=0;
    else
        type(i,1)=1;
    end
end
ind=find(type==1)+1;
hold on
scatter(x(ind),-y(ind),60,'MarkerFaceColor','cyan')
%%
clear Dsum i D DD
Dsum=0;
for i=1:length(x)-1
    D(i,1)=dist([x(i),y(i)],[x(i+1);y(i+1)]);
    Dsum=Dsum+D(i);
end
Dsum
DD=round(D/Dsum*22100);
DDD=cumsum(DD)+1;DDD(end)=[];

figure()
subplot(2,1,1)
plot(DDD,tur*180/pi,'LineWidth',2)
xlabel('x')
ylabel('$ corner\ degree\ range:\ 0\ to\ 180$','Interpreter','latex')
subplot(2,1,2)
plot(DDD,type,'bo-')
xlabel('x')
ylabel('$ corner\ degree\ range:\ 0\ or\ 1$','Interpreter','latex')
save corner_degree DDD type

